package com.swpu.service_remind.controller;


import com.swpu.commonutils.JwtUtils;
import com.swpu.commonutils.R;
import com.swpu.commonutils.ResultEncryption;
import com.swpu.service_drink.service.DrinkService;
import com.swpu.service_remind.entity.DrinkRemind;
import com.swpu.service_remind.service.DrinkRemindService;
import com.swpu.service_user.aop.Decrypt;
import com.swpu.service_user.aop.Encrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chaichai
 * @since 2024-03-10
 */
@RestController
@RequestMapping("/service_remind/drink-remind")
public class DrinkRemindController {

    @Autowired
    private DrinkRemindService drinkRemindService;
    @PostMapping("/saveDrinkRemindSetting")
    @Decrypt
    @Encrypt
    public R saveUserDrinkRemindSetting(@RequestBody ResultEncryption resultEncryption, DrinkRemind drinkRemind, HttpServletRequest request){
        String openid = JwtUtils.getOpenidByJwtToken(request);
        if (openid.isEmpty()){
            return R.error().message("当前用户未登录");
        }
        drinkRemindService.saveUserDrinkRemindSetting(openid,drinkRemind);
        return R.ok();
    }
    @GetMapping("/getDrinkRemindSetting")
    public R getDrinkRemindSetting(HttpServletRequest request){
        String openid = JwtUtils.getOpenidByJwtToken(request);
        if (openid.isEmpty()){
            return R.error().message("当前用户未登录");
        }
        DrinkRemind remindSetting = drinkRemindService.getDrinkRemindSetting(openid);
        return R.ok().data("drinkRemind",remindSetting);
    }


}

